package org.example.review.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.lettuce.core.dynamic.annotation.Param;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import com.common.pojo.entity.OperationLog;
import org.example.review.dto.OperationLogDTO;

import java.util.List;

/**
 * 操作日志数据访问层接口
 */
@Mapper
public interface OperationLogMapper extends BaseMapper<OperationLog> {

    /**
     * 查询指定申请的操作日志列表
     * @return 操作日志列表
     */
    @Select("SELECT " +
            "id, applyid, approval_status, is_changed, remark, create_time,dir,staff,staffid,dep " +
            "FROM t_operation_log " +
            "ORDER BY create_time DESC")
    // 【关键】使用 resultType 指定返回的类型是 DTO
    IPage<OperationLogDTO> selectAllOperationLogs(Page<OperationLogDTO> page);

    /**
     * 插入操作日志记录
     * @param operationLog 操作日志对象
     * @return 影响的行数
     */
    @Insert("INSERT INTO t_operation_log " +
            "(applyid, approval_status, is_changed, remark, create_time,remark,dir,staff,staffid,dep) " + // 新表字段，顺序与 VALUES 对应
            "VALUES " +
            "(#{operationLog.applyid}, #{operationLog.approvalStatus}, #{operationLog.isChanged}, #{operationLog.remark}, #{operationLog.createTime},#{operationLog.remark},#{operationLog.dir},#{operationLog.staff},#{operationLog.staffid},#{operationLog.dep},NOW())") // NOW() 自动取数据库当前时间
    int insertOperationLog(@Param("operationLog") OperationLog operationLog); // 注意：参数是新实体类 TOperationLog
    IPage<OperationLogDTO> selectOperaList(Page<OperationLogDTO> page);
}